forum

home / developersection / forums / if statements in methods

If statements in methods

Anonymous User 1799 13-Nov-2013

I have a variable set in C# that changes depending on which If statement is selected.

But when I try to Console.WriteLine, it tells me the variable does not exist in the current context, could someone help me with this please?

public void mood()
{
  var unhappiness = Hunger + Boredom;
  if (unhappiness < 5)
  {
    string m = "Happy";
  }
  if (unhappiness <= 5 && unhappiness <= 10)
  {
    string m = "Okay";
  }
  if (unhappiness <= 11 && unhappiness <= 15)
  {
    string m = "Frustrated";
  }
  if (unhappiness <= 16)
  {
    string m = "Mad";
  }
  Console.WriteLine(m);
}

c# c# 
Updated on 13-Nov-2013

I am a content writter !


Message
Can you answer this question?

Answer

1 Answers

Liked By